package com.zhiwei.msf.infra.oauth.mapper;

import com.zhiwei.msf.infra.oauth.entity.UserInfo;
import org.apache.ibatis.annotations.*;

import java.util.Date;

public interface UserInfoMapper {

    /**
     * 查询用户信息
     * @param username
     * @return
     */
    @Select("SELECT * FROM user_info WHERE username = #{username}")
    @Results({
            @Result(property = "uuid", column = "uuid", javaType = String.class),
            @Result(property = "username", column = "username", javaType = String.class),
            @Result(property = "password", column = "password", javaType = String.class),
            @Result(property = "phone", column = "phone", javaType = String.class),
            @Result(property = "email", column = "email", javaType = String.class),
            @Result(property = "createTime", column = "create_time", javaType = Date.class),
            @Result(property = "updateTime", column = "update_time", javaType = Date.class)
    })
    public UserInfo getByUsername(String username);

    /**
     * 新增用户信息
     * @return
     */
    @Insert("INSERT INTO user_info values(#{uuid},#{username},#{password},#{phone},#{email},#{createTime},#{updateTime})")
    public int addUser(UserInfo userInfo);

    /**
     * 删除用户
     * @param userId
     * @return
     */
    @Delete("DELETE FROM user_info where uuid = #{userId}")
    int deleteUser(String userId);

    /**
     * 更新用户信息
     * @param userInfo
     * @return
     */
    @Update("UPDATE public.user_info SET password=#{password}, phone=#{phone}, email=#{email},update_time=#{updateTime} WHERE uuid=#{uuid}")
    int updateUser(UserInfo userInfo);

    /**
     * 查询用户信息
     * @param userId
     * @return
     */
    @Select("SELECT * FROM user_info WHERE uuid = #{userId}")
    @Results({
            @Result(property = "uuid", column = "uuid", javaType = String.class),
            @Result(property = "username", column = "username", javaType = String.class),
            @Result(property = "password", column = "password", javaType = String.class),
            @Result(property = "phone", column = "phone", javaType = String.class),
            @Result(property = "email", column = "email", javaType = String.class),
            @Result(property = "createTime", column = "create_time", javaType = Date.class),
            @Result(property = "updateTime", column = "update_time", javaType = Date.class)
    })
    UserInfo getByUserId(String userId);
}